package com.bdsy.system.session;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

public class SessionContext 
{
	public Map<String,HttpSession> sessionMap=new HashMap<String,HttpSession>();
	
	public static SessionContext context=new SessionContext();
	
	private SessionContext()
	{
		 //私有方法，单例
	}
	
	public void addSession(HttpSession session)
	{
		if(session!=null)
		{
			sessionMap.put(session.getId(), session);
		}
	}
	
	public void removeSession(HttpSession session)
	{
		if(session!=null)
		{
			sessionMap.remove(session.getId());
		}	
	}
	
	public HttpSession getSession(String sessionId)
	{
		if(StringUtils.isNotBlank(sessionId))
		{
			return sessionMap.get(sessionId);
		}
		return null;
	}
	
	public synchronized static SessionContext getInstance()
	{
		if(context==null)
		{
			return new SessionContext();
		}
		return context;
	}
}